﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Streambolics
{
    /// <summary>
    ///     An object representing something to do.
    /// </summary>
    /// <remarks><para>
    ///     Jobs represent what needs to be done, not how it should be done.
    /// </para><para>
    ///     For example, a job might represent the need to print a PDF document
    ///     on a given printer. 
    ///     <list type="bullet"><item>
    ///         The job just gives the PDF file and the printer, not the
    ///         algorithm to be applied to actually print the file.
    ///     </item><item>
    ///         The algorithm to be applied is represented by a Job Processor. It 
    ///         is the job processor who will decide whether to render the PDF 
    ///         page by page, or ask Adobe Acrobat to print it.
    ///     </item></list>
    /// </para><para>
    ///     In order for a job to be processed by a Job Processor, it must be
    ///     inserted in a Job Queue. Again, it is not the Job itself that can
    ///     decide on which queue to go.
    /// </para></remarks>

    public class Job
    {
        private bool _Complete;
        private bool _Started;
        private Exception _Failure;

        /// <summary>
        ///     Whether the job is complete.
        /// </summary>

        public bool Complete
        {
            get
            {
                return _Complete;
            }
            internal set
            {
                if (value != _Complete)
                {
                    _Complete = value;
                    DoCompleteChanged ();
                }
            }
        }

        /// <summary>
        ///     Whether the job is started.
        /// </summary>
        
        public bool Started
        {
            get
            {
                return _Started;
            }
            internal set
            {
                if (_Started != value)
                {
                    _Started = value;
                    DoStartedChanged ();
                }
            }
        }

        public event EventHandler CompleteChanged;

        protected virtual void OnCompleteChanged (EventArgs e)
        {
            if (CompleteChanged != null)
            {
                CompleteChanged (this, e);
            }
        }

        protected void DoCompleteChanged ()
        {
            OnCompleteChanged (EventArgs.Empty);
        }

        public event EventHandler StartedChanged;

        protected virtual void OnStartedChanged (EventArgs e)
        {
            if (StartedChanged != null)
            {
                StartedChanged (this, e);
            }
        }

        protected void DoStartedChanged ()
        {
            OnStartedChanged (EventArgs.Empty);
        }
    }
}
